package top.lingkang.authoritypro.data.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import top.lingkang.authoritypro.data.entity.Authority;
import top.lingkang.authoritypro.data.entity.Menu;
import top.lingkang.authoritypro.data.entity.Role;
import top.lingkang.authoritypro.data.entity.User;

import java.util.List;

/**
 * @author lingkang
 * Created by 2021/12/14
 */
@Repository
public interface UserDao extends JpaRepository<User, Long> {
    User findByUsername(String username);

    @Query("select ur.role from UserToRole ur where ur.user=?1")
    List<Role> getRole(User user);

    @Query("select ra.authority from RoleToAuthority ra where ra.role=?1")
    List<Authority> getAuthority(Role role);

    @Query("select rm.menu from RoleToMenu rm where rm.role=?1")
    List<Menu> getMenu(Role role);
}
